package com.park.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.park.model.Paging;
import com.park.model.Park;
import com.park.model.PosChargeData;
import com.park.model.WebUtil;
import com.park.model.WxPaidrecord;
import com.park.service.Utility;
import com.park.service.WxPaidrecordService;
@Controller
@RequestMapping("/wxPaidrecord")
public class WxPaidrecordController {
	@Autowired
	private WxPaidrecordService wxPaidrecordService;
	private static Log logger = LogFactory.getLog(WxPaidrecordController.class);
	
	/*
	 * 添加微信支付订单
	 * @param paidRecord
	 */
	@RequestMapping(value = "/insert", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public String insert(@RequestBody WxPaidrecord paidRecord){
		logger.info("[insert]参数:"+paidRecord);
		Map<String,Object> result = new HashMap<String, Object>();
		boolean count = wxPaidrecordService.insertWxPaidrecord(paidRecord);
		if(count) {
			result.put("status", 1001);
			result.put("message", "添加成功");
		}else {
			result.put("status", 1002);
			result.put("message", "添加失败");
		}
		return Utility.gson.toJson(result);
	}

	/*
	 * 根据userId获取订单
	 * @param webUtil
	 * ruturn
	 */
	@RequestMapping(value = "selectWxPaidrecordListByUserId", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public String selectWxPaidrecordListByUserId(@RequestBody WebUtil webUtil){
		logger.info("[selectWxPaidrecordListByUserId]参数:"+webUtil);
		Map<String,Object> result = new HashMap<String, Object>();
		Map<String,Object> map = new HashMap<String, Object>();
		List<WxPaidrecord> record = wxPaidrecordService.selectWxPaidrecordListByUserIdV2(webUtil);
		int count = wxPaidrecordService.selectWxPaidrecordListByUserIdCount(webUtil);
		List<Park> parks = wxPaidrecordService.getParkByUserId(webUtil);
		Paging page = new Paging(webUtil.getStartPage(),webUtil.getPageSize(),count,record);
		map.put("parkOption", parks);
		map.put("pageInfo", page);
		result.put("status", 1001);
		result.put("message", "查询成功");
		result.put("body", map);
		return Utility.gson.toJson(result);
	}
	
	/*
	 * 根据订单号查询订单
	 * @param webUtil
	 * ruturn
	 */
	@RequestMapping(value = "selectWxPaidrecordByOutTradeNo", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public String selectWxPaidrecordByOutTradeNo(@RequestBody WebUtil webUtil){
		logger.info("[selectWxPaidrecordListByUserId]参数:"+webUtil);
		Map<String,Object> result = new HashMap<String, Object>();
		WxPaidrecord record = wxPaidrecordService.selectWxPaidrecordByOutTradeNo(webUtil.getOutTradeNo());
		result.put("status", 1001);
		result.put("message", "查询成功");
		result.put("body", record);
		return Utility.gson.toJson(result);
	}
}
